package com.lancoo.answer.view.fragment.translate;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lancoo.answer.R;
import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.model.bean.Type;
import com.lancoo.answer.widget.combinationView.QueseBodyView;
import com.lancoo.answer.widget.combinationView.WritingAnswerResultView;

import java.util.List;

/**
 * Created by pengmi on 2021/12/10 15:02
 * Description:翻译题小题查看评阅fragment
 */
public class TranslateChapterAnswerLookingFragment extends Fragment {


    private Child child;
    private View convertView;
    private static final String TAG = "PassageDictationLooking";
    private int kindIndex;
    private int queseIndex;
    private int smallQueseIndex;
    private WritingAnswerResultView writingAnswerResultView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        convertView=inflater.inflate(R.layout.ev_fragment_passage_dictation_looking_layout,container,false);
        return convertView;
    }


    public static Fragment loadQueseFragment(int kindIndex, int queseIndex, int smallQueseIndex){

        TranslateChapterAnswerLookingFragment queseFragment=new TranslateChapterAnswerLookingFragment();
        Bundle mBundle=new Bundle();
        mBundle.putInt("kindIndex",kindIndex);
        mBundle.putInt("queseIndex",queseIndex);
        mBundle.putInt("smallQueseIndex",smallQueseIndex);
        queseFragment.setArguments(mBundle);
        return queseFragment;
    }



    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view){
        Log.e(TAG,"initView"+(child==null));
        if(getArguments()==null){
            return;
        }
        kindIndex = getArguments().getInt("kindIndex");
        queseIndex = getArguments().getInt("queseIndex");
        smallQueseIndex = getArguments().getInt("smallQueseIndex");

        List<Type> kindBeanListk = ConstantBean.Companion.getConstantExamBean().getTypeList();
        Ques ques = kindBeanListk.get(kindIndex).getQuesList().get(queseIndex);
        child =ques.getChildList().get(smallQueseIndex);
        QueseBodyView queseBodyView = view.findViewById(R.id.quese_body_view);
        queseBodyView.setEnableShowChildAsk(false);
        queseBodyView.initData(child);
        String genreID = ques.getGenreID();
        writingAnswerResultView = view.findViewById(R.id.writing_answer_result);

        writingAnswerResultView.setWriteResult(child,genreID,ques.getQuesID());
//        if(TextUtils.equals(genreID,"51")||
//                TextUtils.equals(genreID,"50")){
//            queseBodyView.setVisibility(View.GONE);
//        }

    }

    @Override
    public void onResume() {
        super.onResume();
        if(writingAnswerResultView!=null){
            writingAnswerResultView.updateScoreState();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if(writingAnswerResultView!=null){
            writingAnswerResultView.onPause();
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if(writingAnswerResultView!=null){
            writingAnswerResultView.release();
        }
    }

    public void adjustFontSize(){
        if(convertView==null){
            return;
        }
        QueseBodyView queseBodyView=convertView.findViewById(R.id.quese_body_view);
        queseBodyView.adjustFontSize();
        writingAnswerResultView.adjustFontSize();

    }

}
